using Microsoft.EntityFrameworkCore;
using UniversalAdminSystem.Domian.Core.Interfaces;
using UniversalAdminSystem.Domian.LogManagement.Aggregates;
using UniversalAdminSystem.Domian.LogManagement.IRepository;
using UniversalAdminSystem.Infrastructure.Persistence.DbContexts;

namespace UniversalAdminSystem.Infrastructure.Persistence.Repositories;

public class LogEntryRepository : BaseRepository<LogEntry>, ILogEntryRepository
{
    public LogEntryRepository(UniversalAdminSystemDbContext context) : base(context)
    {
    }

    public async Task<IEnumerable<LogEntry>> GetByLevelAsync(string level)
    {
        return await _DbContext.Set<LogEntry>()
            .Where(l => l.Level == level)
            .ToListAsync();
    }

    public async Task<IEnumerable<LogEntry>> GetByUserAsync(Guid userId)
    {
        return await _DbContext.Set<LogEntry>()
            .Where(l => l.UserId.Value == userId)
            .ToListAsync();
    }

    public async Task<IEnumerable<LogEntry>> GetByDateRangeAsync(DateTime start, DateTime end)
    {
        return await _DbContext.Set<LogEntry>()
            .Where(l => l.Timestamp >= start && l.Timestamp <= end)
            .ToListAsync();
    }

    public async Task<IEnumerable<LogEntry>> GetBySourceAsync(string source)
    {
        return await _DbContext.Set<LogEntry>()
            .Where(l => l.Source == source)
            .ToListAsync();
    }
} 